package Modelo;

import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import javax.swing.JFileChooser;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class CargarArchivoCvs extends javax.swing.JFrame
{

	private static final long serialVersionUID = 1L;

	public void exportar(String[][]data)
	{
		JFileChooser fileChooser=new JFileChooser();
		fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		int resultado=fileChooser.showSaveDialog(this);
		if(resultado==JFileChooser.CANCEL_OPTION)
		{
			return;
		}
		File archivo= fileChooser.getSelectedFile();
		try{
	
			PrintWriter salida= new PrintWriter(new FileWriter(archivo+".csv"));
			
			for(int i=0;i<data.length;i++)
			{
				salida.print(data[i][0]);
				for(int j=1;j<data[i].length;j++)
				{
					String word=data[i][j];
					
					if(word!=null){
						salida.print(";"+word);
						
					}else{
						salida.print(";");
					}
				}
				salida.println();
			}
			salida.close();
		}catch (Exception io) {
			 io.getMessage();
		}
		
	}

	
}